import { observable } from "mobx"
import storage from "good-storage"
import themes from "../pages/upload/themes"

const UserStore = observable({
  watchRule: storage.get("watchRule") || false, // 是否查看 rule
  isPostOrGetData: false,
  postOrGetDataMsg: "",
  repeatUploadFlag: false,
  firstLoading: false,
  errorPop: false,
  errorMsg: "",
  ruleFlag: storage.get("ruleFlag") || false,
  token: storage.get("token") || "",
  // 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTM4NDI2NjgsImlkIjoiNCIsIm5pY2tuYW1lIjoiY2FwdGVybiIsIm9wZW5pZCI6Im9PNjJHdUp1RjdKeGFFRHVJMGhIMEdVclJLYVEiLCJvcmlnX2lhdCI6MTU5Mzc1NjI2OCwidmVyc2lvbiI6IjE1OTM3NTYyNjgifQ.Vhe7o6yZxehUj76WmjyChyYfv4PBj6WfodHMkXbAF2g',
  headimgurl: storage.get("headimgurl") || "",
  status: storage.get("userStatus") || "method",
  // methodMsg 填写报名学习还是家庭的信息
  mode: storage.get("mode") || 1, // 参赛模式  参赛模式 1：学校 2：家庭
  theme: storage.get("theme") || 1, // 主题
  themeIndex: storage.get("themeIndex") || 0,
  themeChild: storage.get("themeChild") || 1, // 副主题
  themeChildIndex: storage.get("themeChildIndex") || 0,

  // 个人信息部分
  school: storage.get("school") || "", // 学校
  phone: storage.get("phone") || "", // 手机
  child_name: storage.get("child_name") || "", // 孩子名
  age: storage.get("age") || "", // 年龄
  teacher_name: storage.get("teacher_name") || "", // 老师名
  description: storage.get("description") || "", // 作品描述
  head_image_url: "",
  imgsArray: storage.get("imgsArray") || ["", "", "", ""], // 上传的图片
  uploadDesc: storage.get("uploadDesc") || "", // 上传作品描述

  offLineFlag: false,
  needUpdateAuth: false,

  async changeUserState(status) {
    this.status = status
    storage.set("userStatus", status)
  },
  async changeMethod(method) {
    this.mode = method
    storage.set("mode", method)
  },
  async changeTheme(theme, index) {
    this.theme = theme
    this.themeIndex = index
    this.themeChild = themes[index].childrens[0].key
    this.themeChildIndex = 0
    storage.set("theme", theme)
    storage.set("themeIndex", index)
    storage.set("themeChild", themes[index].childrens[0].key)
    storage.set("themeChildIndex", 0)
  },
  async changeThemeChild(themeChild, index) {
    this.themeChild = themeChild
    this.themeChildIndex = index
    storage.set("themeChild", themeChild)
    storage.set("themeChildIndex", index)
  },
  async changeValus(key, value) {
    this[key] = value
    storage.set(key, value)
  },
  async setToken(token) {
    this.token = token
    storage.set("token", token)
  },
  async setImgsArray(url, index) {
    this.imgsArray[index] = url
    storage.set("imgsArray", this.imgsArray)
  },
  // async setUploadDesc(uploadDesc) {
  //   this.uploadDesc = uploadDesc
  //   storage.set('uploadDesc', uploadDesc)
  // },
  async setErrorMsg(flag, msg) {
    this.errorPop = flag
    this.errorMsg = msg
  },
  async setPostOrGetData(flag, msg) {
    this.isPostOrGetData = flag
    this.postOrGetDataMsg = msg
  },

  // 获取首页数据
  async getList() {
    // this.title = '傻逼前端'
    // this.list = await HomeApi.getList();
  },
  async setAccessToken(accessToken) {
    this.accessToken = accessToken
  },
  async setUid(uid) {
    this.uid = uid
  },
  async setOffLine(flag) {
    this.offLineFlag = flag
  },
  async setNeedUpdateAuth(flag) {
    this.needUpdateAuth = flag
  },
  async setWatchRule(flag) {
    this.watchRule = flag
    storage.set("watchRule", flag)
  },
})

export default UserStore
